<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <script src="../application/vue.js"></script>
</head>
<body>
    <div id="app">
        <p>msg:{{msg}}</p>
        <input type="text" v-model="msg">
        <hr>
        <p>obj.info:{{obj.info}}</p>
        <input type="text" v-model="obj.info">
        <comp-a :msg.sync="msg" :obj="obj"></comp-a>
    </div>
    <template id="child">
        <div>
            <p>msg:{{msg}}</p>
            <input type="text" v-model="getMsg">
            <input type="button" value="赋值" @click="$emit('update:msg','新值')">
            <hr>
            <p>obj.info:{{obj.info}}</p>
            <input type="text" v-model="obj.info">
        </div>
    </template>
</body>
<script>
    new Vue({
        el:"#app",
        components:{
            compA:{
                template:"#child",
                props:{
                    msg:{
                        type:String
                    },
                    obj:{
                        type:Object
                    }
                },
                computed:{
                    getMsg:{
                        get(){
                            // console.log(this);
                            return this.msg;
                        },
                        set(nv){
                            this.$emit("update:msg",nv);
                        }
                    }
                }
            }
        },
        data:{
            msg:"父组件变量",
            obj:{
                info:"info变量"
            }
        }
    })
</script>
</html>